import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'home_screen.dart';
import 'shop/shop_screen.dart';
import 'data_screen.dart';
import 'profile_screen.dart';
import 'tabBarProvider.dart';


class TabBarWidget extends StatelessWidget {

  final List<BottomNavigationBarItem> _tabBtns = [];
  final List<Widget> _tabPags = [];

  @override
  Widget build(BuildContext context) {

    BottomNavigationBarItem _homeItem = BottomNavigationBarItem(
      icon: Icon(Icons.home,color: Colors.black26),
      activeIcon: Icon(Icons.home,color: Colors.blue),
      title: Text('首页',style: TextStyle(color: Colors.blue))
    );

    BottomNavigationBarItem _shopItem = BottomNavigationBarItem(
      icon: Icon(Icons.store,color: Colors.black26),
      activeIcon: Icon(Icons.store,color: Colors.blue),
      title: Text('门店',style: TextStyle(color: Colors.blue))
    );

    BottomNavigationBarItem _dataItem = BottomNavigationBarItem(
      icon: Icon(Icons.data_usage,color: Colors.black26),
      activeIcon: Icon(Icons.data_usage,color: Colors.blue),
      title: Text('数据',style: TextStyle(color: Colors.blue))
    );

    BottomNavigationBarItem _profileItem = BottomNavigationBarItem(
      icon: Icon(Icons.person,color: Colors.black26),
      activeIcon: Icon(Icons.person,color: Colors.blue),
      title: Text('我',style: TextStyle(color: Colors.blue))
    );

    _tabBtns.add(_homeItem);
    _tabBtns.add(_shopItem);
    _tabBtns.add(_dataItem);
    _tabBtns.add(_profileItem);

    _tabPags.add(HomeScreen());
    _tabPags.add(ShopScreen());
    _tabPags.add(DataScreen());
    _tabPags.add(ProfileScreen());

    return Consumer<TabBarProvider>(
      builder: (context,TabBarProvider tabProvider,child){
        return Scaffold(
          bottomNavigationBar: BottomNavigationBar(
            type: BottomNavigationBarType.shifting,
            currentIndex: tabProvider.value,
            items: _tabBtns,
            onTap: (tapIndex){
              print('点击了$tapIndex');
              tabProvider.changeIndex(tapIndex);
            },
          ),
          body: IndexedStack(
            index: tabProvider.value,
            children: _tabPags,
          ),
        );
      },
    );
  }
}